from dbs import Dao


class UserDao(Dao):
    def login(self, name, pwd):
        return self.query('tb_user', 'id', 'phone', 'nick_name', 'head', 'is_active',
                          where='username=%s and auth_string=%s', args=(name, pwd), one=True)

    def update_detail(self, **item):
        return self.update('tb_user', **item)

    def get_user_active_state(self,id):
        return self.query('tb_user', 'id', 'username', 'is_active',
                    where='id=%s', args=(id,), one=True)

    def is_user_active(self, id):
        """用户是否激活"""
        return self.query('tb_user', 'id', where='id=%s and is_active=1', args=(id,), one=True)

    def active(self, id):
        return self.update('tb_user', id=id, is_active=1)

    def check_user_name(self, username):
        return self.query('tb_user', 'id', where='username=%s', args=(username, ), one=True)

    def save(self, **item):
        # super()调用父类的方法
        return super().save('tb_user', **item)